home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
fieldent.zip
/
FIELDS.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-01-04
|
26KB
|
850 lines
{$V-} (* relaxed string paramater type checking *)
Unit Fields;
(*
Screen I/O for fields.
Based on IBM System 23/Datamaster computer from 1981-1984
code by John Tal
Rollins Medical/Dental Systems
Southfield, MI
*******************
* Public Domain *
*******************
Modula-2 versions available in Compuserve Musus sig in JTM2LIB.ARC
Basic versions for QB4 available from author at RBBS (313) 423-7211
Note: To Re-Compile this unit you need
Pwindow.Arc
DosBios.Arc
Funcs.Arc
All should be available from this Compuserve dl and
also from the author via RBBS (313) 423-7211
*)
(*
History behind Fields is in Fields.Me file
Command String Details
----------------------
SCR1$(1) = "02,34,C 08,au," + Ed_nor_str
^ 02 = 2 digits Y screen location
^ 34 = 2 digits X location
^ C & a space always (C = character data)
Although Character data is the only type
currently supported by this emulation, the
original types included
V = Variable length character data
( Trailing blanks dropped )
C = Character
( Trailing blanks retained )
N = Numeric
( 04,04,N 12.2,AU,N = #########.##
^ field width
G = Both character & numeric
If data is character, acts like V
If data is numeric, acts like N
PIC = Picture format, like print using mask
( Not supported on input fields )
^ 08 = 2 digits field width
^ au = variable combination of field attributes
upper or lower case.
I = invisible
U = underline
B = blink
H = highlight
R = reverse
N = normal
A = auto-exit at end of field
( goes to next field )
E = auto-return at end of field
( ii set to -2, end of processing
for all fields in this screen )
This last field is usually a N for normal, but can
be a two letter combination specifying foreground
and background colors.
(fB) foreground color is specified by a lower case letter
BACKGROUND color in UPPER CASE
Foreground defined as follows
d = Black
r = Red
g = Green
y = Yellow
b = Blue
m = magenta
c = cyan
w = white
Background are the same colors with letters in caps
the declaration of bW would be blue letters on a
white background. The foreground colors can be
raised to high intensity by specifying a H in the
field attribute position defined above.
04,04,C 10,au,yC = brown letters on cyan background
04,04,C 10,ah,yC = yellow letters on cyan background
Color variable definitions
--------------------------
Integers
colf[fore,0],colf[back,0] Main Text foreground background
colf[fore,1],colf[back,1] Editable field passive colors
colf[fore,2],colf[back,2] Editable field active colors
colf[fore,3],colf[back,3] Editable field in error (reversed)
colf[fore,4],colf[back,4] Main Text in reverse
Strings
Ed_nor_str Editable field passive colors
Ed_cur_str Editable field active colors
Ed_err_str Editable field in error (reversed)
Ed_scr_str Main Text in reverse
*)
Interface
Uses Crt,Funcs,DosBios;
CONST
MonoChrome = 1;
BlackWhite = 2;
Color = 3;
scr_def_str = 'DBGCRMYWdbgcrmyw';
fore = 1;
back = 2;
TYPE
st255 = string[255];
IntAry25 = ARRAY[1..2,0..4] OF Integer;
StrAry25 = ARRAY[1..2,0..4] OF st255;
StrAry4 = ARRAY[1..4] OF st255;
FrameAry = ARRAY[1..12] OF Byte;
BoxItAryStr = ARRAY[1..25] Of st255;
VAR
Frame: FrameAry;
Procedure FigScreenAttrib(scr_type: Integer; ctrl_atr,disp_atr: st255;
VAR text_color,text_bak: Integer; VAR disp_color: BYTE);
procedure field_out(scr_type,
norm_for,
norm_bak: Integer;
scr_ctrl,
show_data : st255);
procedure field_in(scr_type,
norm_for,
norm_bak: Integer;
scr_ctrl: st255;
var buf78 : st255;
var flen,ii : integer);
Procedure SetIoCol(scr_type: Integer;
colf : IntAry25;
cols : StrAry25;
VAR Intens : StrAry4;
VAR Ed_cur_str,
Ed_nor_str,
Ed_err_str,
Ed_scr_str : st255);
Procedure DrawBox(Frame: FrameAry; Bx,By,Bw,Bh: Integer);
Procedure Boxit(bx,by: Integer;
Cout: BoxItAryStr;
Cout9,
Spac: Integer;
VAR Scrf: BoxItAryStr;
VAR Scrf9: Integer;
Frame: FrameAry;
colf: IntAry25;
scr_type: Integer;
VAR rx,ry,rw,rh: BYTE;
buff_ptr: scr_buffer_ptr);
(* paramater breakdown
Boxit(bx, = screen X pos (-1 = center)
by, = screen Y pos (-1 = center)
Cout, = array of strings to define screen.
Ascii 196 in string means full horiz bar
Underscores (Ascii 95) denotes input field
Cout9, = number of cout[]'s defined
Spac = line spacing between entries
Negative values mean line spacing of
abs(spac) and each line centered
Scrf, = returned field definitions
(make sure to dim enough)
Scrf9, = number of Scrf[]'s returned
Frame, = array graphic box defs
colf, = integer color defs
scr_type = screen type
*)
Procedure InitFrame;
Implementation
Procedure FigScreenAttrib(scr_type: Integer; ctrl_atr,disp_atr: st255;
VAR text_color,text_bak: Integer; VAR disp_color: BYTE);
VAR
col_for,col_bak: Integer;
BEGIN
UpStr(ctrl_atr);
UpStr(disp_atr);
CASE scr_type OF
MonoChrome: begin
disp_color := 7;
if pos('I',ctrl_atr) <> 0 then disp_color := disp_color xor 1;
if pos('U',ctrl_atr) <> 0 then disp_color := disp_color xor 6;
if pos('B',ctrl_atr) <> 0 then disp_color := disp_color or 16;
if pos('H',ctrl_atr) <> 0 then disp_color := disp_color or 8;
if pos('R',ctrl_atr) <> 0 then disp_color := 112;
if disp_color = 112 then begin
text_color := 0;
text_bak := 7;
end
ELSE begin
text_color := disp_color;
text_bak := 0;
END;
if (disp_color >= 17) and (disp_color <> 112) THEN
disp_color := disp_color + 112; { must add 112 to get effect for poke }
end;
BlackWhite,Color: begin
col_for := Pos(Upcase(disp_atr[1]),scr_def_str)-1; (* disp = colors *)
col_bak := Pos(Upcase(disp_atr[2]),scr_def_str)-1;
disp_color := col_for + col_bak * 16;
text_color := col_for;
text_bak := col_bak;
if pos('H',ctrl_atr) <> 0 then begin
disp_color := disp_color + 8;
text_color := text_color + 8;
end;
(* writeln(disp_color,' ',col_for,' ',col_bak); *)
end;
END;
END;
procedure field_out;
(* (norm_for,norm_bak,scr_type: Integer; scr_ctrl : st255; show_data : st255); *)
VAR
scr_y,scr_x,scr_l,i : integer;
screen_mem_org : integer;
ca : array[1..5] of st255;
c,comma,text_color,text_bak : integer;
disp_color: BYTE;
disp_atr,ctrl_atr : st255;
chold : st255;
col_for,col_bak: Integer;
vchar,vattrib: Byte;
command: char;
begin
chold := scr_ctrl;
for c := 1 to 5 do { pass 1 - isolate y }
begin { 2 - isolate x }
comma := pos(',',chold); { 3 - isolate C and width }
if comma = 0
then
comma := length(chold)+1;
ca[c] := copy(chold,1,comma-1); { 4 - isolate display attrib }
chold := copy(chold,comma+1,255); { 5 - isolate control attrib }
end;
scr_y := fnval(ca[1]);
scr_x := fnval(ca[2]);
scr_l := fnval(right_str(ca[3],2));
disp_atr := ca[4];
ctrl_atr := ca[5];
FigScreenAttrib(scr_type,disp_atr,ctrl_atr,text_color,text_bak,disp_color);
textcolor(text_color);
textbackground(text_bak);
gotoxy(scr_x,scr_y);
write(show_data);
for i := scr_x to (scr_x + scr_l - 1) do begin
Put_CurSor(i,scr_y);
Get_Vattrib(vchar,vattrib);
Put_Vattrib(vchar,disp_color);
end;
textcolor(norm_for);
textbackground(norm_bak);
gotoxy(scr_x,scr_y);
end; {proc outfield}
procedure field_in;
(* (norm_for,norm_bak,scr_type: Integer; scr_ctrl : st255; var buf78 : st255; var flen,ii : integer); *)
var
scr_y,scr_x,scr_l : integer;
cur_y,cur_x : integer;
screen_mem_org,i,writ_char,move_cursor,action : integer;
fielding,specialkey : boolean;
tempx,tempy : integer;
chold : st255;
ca : array[1..5] of st255;
c,comma,text_color,text_bak : integer;
disp_color: BYTE;
disp_atr,ctrl_atr : st255;
command: char;
vchar,vattrib: byte;
col_for,col_bak: Integer;
procedure proc_move_cursor( moveit : integer);
begin
case moveit of
1 : begin {move cursor to right}
cur_x := cur_x + 1;
if cur_x > (scr_x + scr_l -1)
then
cur_x := scr_x;
gotoxy(cur_x,cur_y);
end;
2 : begin {move cursor to left}
cur_x := cur_x - 1;
if cur_x < scr_x
then
cur_x := (scr_x + scr_l - 1);
gotoxy(cur_x,cur_y);
end;
end; {case moveit}
end; {proc_move_cursor}
procedure proc_writ_char (writ : integer);
begin
case writ of
0 : delay(1);
1 : begin
gotoxy(cur_x,cur_y);
write(command);
if cur_x +1 > (scr_x + scr_l -1)
then
gotoxy(scr_x,scr_y);
end;
2 : begin
gotoxy(cur_x,cur_y);
write(' ');
gotoxy(cur_x,cur_y);
end;
3 : begin
gotoxy(cur_x,cur_y);
write(spaces((scr_x + scr_l) - cur_x));
gotoxy(scr_x,scr_y);
end;
end; {case writ}
end; {proc_writ_char}
begin
chold := scr_ctrl;
for c := 1 to 5 do begin { pass 1 - isolate y }
{ 2 - isolate x }
comma := pos(',',chold); { 3 - isolate C and width }
if comma = 0
then
comma := length(chold)+1;
ca[c] := copy(chold,1,comma-1); { 4 - isolate display attrib }
chold := copy(chold,comma+1,255); { 5 - isolate control attrib }
end;
scr_y := fnval(ca[1]);
scr_x := fnval(ca[2]);
scr_l := fnval(right_str(ca[3],2));
disp_atr := ca[4];
ctrl_atr := ca[5];
FigScreenAttrib(scr_type,disp_atr,ctrl_atr,text_color,text_bak,disp_color);
gotoxy(scr_x,scr_y);
writeln(buf78);
for i := scr_x to (scr_x + scr_l - 1) do begin
Put_Cursor(i,scr_y);
Get_Vattrib(vchar,vattrib);
Put_Vattrib(vchar,disp_color);
end;
gotoxy(scr_x,scr_y);
cur_y := scr_y;
cur_x := scr_x;
buf78 := spaces(78);
textcolor(text_color);
textbackground(text_bak);
fielding := true;
repeat
if inkey(specialkey,command) Then begin { if a key has been pressed }
if not specialkey Then begin { if not arrow key or tabs }
if ord(command) in [32..126] Then begin { if alpha-numeric, accept and print }
writ_char := 1; { write the character }
move_cursor := 1; { move cursor to right }
action := 1; { write/move }
end
else { not alpha-numeric - not special key }
case command of
#13 : begin { carriage return }
fielding := false; { get out of here }
writ_char := 0; { don't write anything }
move_cursor := 0; { don't move the cursor }
action := 0; { don't do anything }
ii := -2; { flag that infield loop is over }
end;
#8 : begin { back-space }
writ_char := 2; { write a space }
move_cursor := 2; { move to left }
action := 3; { move cursor/write blank/re-pos cur }
end;
#9 : begin { Tab }
fielding := false; { get out of here }
writ_char := 0; { don't write anything }
move_cursor := 0; { don't move the cursor }
action := 0; { don't do anything }
ii := ii + 1; { increment control variable }
end;
#27 : begin { Escape }
fielding := false; { get out of here }
writ_char := 3; { write spaces in field }
move_cursor := 0; { don't move the cursor }
action := 4; { write spaces in field }
ii := ii + 1; { increment control variable }
end;
end; {case command}
end {if not specialkey}
else begin
{ begin special keys }
case command of
#75 : begin { left arrow }
writ_char := 0; { don't write anything }
move_cursor := 2; { move to left }
action := 2; { just move }
end;
#77 : begin { right arrow }
writ_char := 0; { don't write anything }
move_cursor := 1; { move to right }
action := 2; { just move }
end;
#72 : begin { Up arrow key }
fielding := false; { get out of here }
writ_char := 0; { don't write anything }
move_cursor := 0; { don't move the cursor }
action := 0; { don't do anything }
ii := ii - 1; { decrement control variable }
end;
#80 : begin { Dn arrow key }
fielding := false; { get out of here }
writ_char := 0; { don't write anything }
move_cursor := 0; { don't move the cursor }
action := 0; { don't do anything }
ii := ii + 1; { increment control variable }
end;
#15 : begin { shift tab }
fielding := false; { get out of here }
writ_char := 0; { don't write anything }
move_cursor := 0; { don't move the cursor }
action := 0; { don't do anything }
ii := ii - 1; { decrement control variable }
end;
#65 : halt; { function key 7 / for testing }
end; {case command}
end; {if specialkey }
case action of
0 : delay(1);
1 : begin
proc_writ_char(writ_char);
proc_move_cursor(move_cursor);
end;
2 : proc_move_cursor(move_cursor);
3 : begin
proc_move_cursor(move_cursor);
proc_writ_char(writ_char);
end;
4 : proc_writ_char(writ_char);
end; {case action}
end; {if inkey}
until not fielding;
buf78 := spaces(78);
for i := scr_x to (scr_x + scr_l - 1) do begin
Put_Cursor(i,scr_y);
Get_Vattrib(vchar,vattrib);
buf78[i-scr_x+1] := chr(ord(vchar));
(* chr(peek(screen_mem_org,(scr_y-1)*160+(i*2)-2)); *)
if buf78[i-scr_x+1] = '_' then
buf78[i-scr_x+1] := ' ';
end;
buf78 := rtrm(copy(buf78,1,scr_l));
flen := length(buf78);
if flen = 0 then begin
flen := scr_l;
buf78 := spaces(scr_l);
end;
textcolor(norm_for);
textbackground(norm_bak);
end; {infield}
Procedure SetIoCol;(* (scr_type: Integer;
colf : IntAry25;
cols : StrAry25;
Intens : StrAry4;
Ed_cur_str,
Ed_nor_str,
Ed_err_str,
Ed_scr_str : st255); *)
VAR
n_str: st255;
i,temp_int : Integer;
BEGIN
n_str := 'DBGCRMYW';
For i := 1 TO 4 DO begin
temp_int := (colf[fore,i] mod 8) + 1;
cols[fore,i] := chr(ord(n_str[temp_int]) + 32);
If colf[fore,i] <= 7 Then
Intens[i] := ''
ELSE
Intens[i] := 'h';
cols[back,i] := n_str[(colf[back,i] MOD 8)+ 1];
END;
If (Scr_type <> Color) Then
Ed_nor_str := 'au,' + cols[fore,1] + cols[back,1]
ELSE
Ed_nor_str := 'a,' + cols[fore,1] + cols[back,1];
Ed_cur_str := 'a' + Intens[2] + ',' + cols[fore,2] + cols[back,2]; { Cmnd_str := '13,57,C 01,' + Ed_cur_str }
Ed_err_str := Intens[3] + 'r,' + cols[fore,3] + cols[back,3]; { Cmnd_str := Copy(Cmnd_str,1,11) + Ed_err_str }
Ed_scr_str := Intens[4] + ',' + cols[fore,4] + cols[back,4];
END;
Procedure InitFrame;
BEGIN
frame[1] := 218;
frame[2] := 196;
frame[3] := 191;
frame[4] := 179;
frame[5] := 192;
frame[6] := 217;
frame[7] := 197;
frame[8] := 195;
frame[9] := 180;
frame[10] := 193;
frame[11] := 194;
frame[12] := 219;
END;
Procedure DrawBox;
(* (Frame: FrameAry; Bx,By,Bw,Bh: Integer); *)
VAR
i : Integer;
BEGIN
Gotoxy(Bx,By);
Write(chr(Frame[1]));
Write(rpt(BW-2,Frame[2]));
Write(chr(Frame[3]));
FOR i := BY+1 TO BY+BH-2 DO begin
Gotoxy(Bx,i);
Write(chr(Frame[4]));
Gotoxy(Bx+Bw-1,i);
Write(chr(Frame[4]));
END;
Gotoxy(Bx,By+Bh-1);
Write(chr(Frame[5]));
Write(rpt(Bw-2,Frame[2]));
Write(Chr(Frame[6]));
END;
Procedure Boxit;
(* (bx,by: Integer;
Cout: BoxItAryStr;
Cout9,
Spac: Integer;
VAR Scrf: BoxItAryStr;
VAR Scrf9: Integer;
Frame: FrameAry;
colf: IntAry25;
scr_type: Integer;
rx,ry,rw,rh: BYTE;
buff_ptr: Scr_buffer_ptr);
*)
VAR
Center,
Ret_save,
Dash : BOOLEAN;
Bw,
Bh,
Max_w,
i,
Old_Scrf9: Integer;
A_str,
D_str: st255;
Xoffs,
Apos,
Dsh,
Field_start_pos,
Dlen,
X,
J,
Tempx,
Tempy,
Tempw : Integer;
Ed_scr_str,ED_nor_str,Ed_err_str,Ed_cur_str,disp_atr,ctrl_atr: st255;
text_color,text_bak: Integer;
disp_color: BYTE;
cols: StrAry25;
Intens : StrAry4;
BEGIN
SetIoCol(scr_type,colf,cols,Intens,Ed_cur_Str,Ed_nor_str,Ed_err_str,Ed_scr_str);
disp_atr := Copy(Ed_scr_str,1,Pos(',',Ed_scr_str)-1);
ctrl_atr := Copy(Ed_scr_str,Pos(',',Ed_scr_str)+1,255);
FigScreenAttrib(scr_type,disp_atr,ctrl_atr,text_color,text_bak,disp_color);
IF Spac <= 0 THEN begin
Spac := Abs(Spac);
Center := True;
end
ELSE
Center := FALSE;
IF Cout9 < 0 THEN begin
Cout9 := Abs(Cout9);
Ret_save := TRUE;
end
ELSE
Ret_save := FALSE;
Max_W := 0;
For i := 1 TO Cout9 Do
Max_W := FnMax(Max_W,Length(COUT[I]));
Bw := Max_W + 6;
Bh := Cout9*Spac + Spac+1;
If Bx = -1 Then (* FLAG TO CENTER BOX HORIZONTALLY ON SCREEN *)
BX := 40-(Bw div 2);
IF BY = -1 THEN (* FLAG TO CENTER BOX VERTICALLY ON SCREEN *)
BY := 12-(Bh div 2);
(*
IF Ret_Save Then
GOTO _RSAVE;
*)
TextColor(colf[fore,4]);
TextBackGround(colf[back,4]);
Rx := Bx;
Ry := By;
Rw := Bw;
Rh := Bh;
Wget(Bx,By,Bw,Bh,buff_ptr);
(* save current area under new window/box *)
Scroll_Page_up(Bx,By,Bw,Bh,bh,disp_color);
(* clear out window/box *)
DrawBox(Frame,Bx,By,Bw,Bh);
Scrf9 := 0;
For i := 1 To Cout9 Do Begin
Old_Scrf9 := Scrf9;
A_str := COUT[i];
If Center Then
Xoffs := (BW div 2) - (Length(A_str) div 2)
Else
Xoffs := 0;
Apos := 1;
(* RETAIN CURRENT CHARACTER FOR SCAN, USED TO DETRM FIELD STARTING POS *)
Dash := (Pos('_',A_str) > 0);
While ((Length(A_str) > 1) AND Dash) DO Begin
(* ANY FIELDS IN THIS STRING? *)
If Dash Then begin
Dsh := Pos('_',A_str);
Field_Start_Pos := Apos + Dsh - 1;
(* THIS FIELD BEGINS AT CURRENT SCAN POS CHAR IN STRING *)
Apos := Field_Start_Pos;
(* WE DID AN INSTR, SO WE HAVE TO ADD WHERE IT WAS FOUND TO LAST *)
(* PLACE WE WERE AT *)
Scrf9 := Scrf9 + 1;
(* A NEW COMMAND STRING FOR Fields *)
D_str := Copy(A_str,Dsh,255);
(* ISOLATE BEGINNING OF DASHS FOR SCAN TO DETERMINE TOTAL *)
(* FIELD LENGTH *)
Dlen := 0;
(* START OFF FIELD LENGTH AS ZERO *)
WHILE Dash DO begin
Dlen := Dlen + 1;
D_str := Copy(D_str,2,255);
Dash := (D_str[1] = '_');
Apos := Apos + 1;
(* INC OVERALL POSITION IN MAIN STRING *)
(* CHOP OFF STRING ON LEFT, CHECKING FOR MORE '_' *)
IF length(d_str) = 0 then dash := false;
END;
Scrf[Scrf9] := fns_z(By+(i*Spac)) + ',' +
fns_z(Bx+Field_Start_Pos+2) + ',C ' +
fns_z(Dlen) + ',' + Ed_Nor_str;
IF Center THEN
Mid_str_assign(Scrf[Scrf9],4,2,fns_z(Bx+Xoffs+Field_Start_Pos-1));
(* BUILD COMMAND STRING *)
A_str := ' ' + D_str; (* PLACE HOLDER, RETAINS POS *)
Apos := Apos - 1;
END; (* If Dash *)
A_str := Copy(A_str,2,255);
Apos := Apos + 1;
Dash := (Pos('_',A_str) > 0);
END;
X := Pos('_',COUT[i]);
While X > 0 DO begin
COUT[I][X] := ' ';
X := Pos('_',COUT[i]);
END;
If COUT[i][1] <> '─' Then begin
If Center Then
GotoXy((BX+XOFFS),BY+(I*SPAC))
Else
GotoXy((Bx + 3), BY+(I*SPAC));
WriteLn(Cout[i]);
end
ELSE begin
GotoXy(Bx,BY+(I*SPAC));
Write('├');
Write(Rpt(BW-2,ord('─')));
Write('┤');
END;
TextColor(colf[fore,1]);
TextBackGround(colf[back,1]);
For J := Old_Scrf9 + 1 To Scrf9 DO begin
Tempy := fnVAL(Copy(SCRF[J],1,2));
Tempx := fnVAL(Copy(SCRF[J],4,2));
TEMPW := fnVAL(Copy(SCRF[J],9,2));
Gotoxy(Tempx,Tempy);
Write(' ':Tempw);
END;
TextColor(colf[fore,4]);
TextBackground(colf[back,4]);
END; (* Next I *)
TextColor(colf[fore,0]);
TextBackground(colf[back,0]);
END; (* Boxit *)
END.